import axios, { ResDataType } from './ajax'

type SearchOption = {
    keyword: string
    isStar: boolean
    isDeleted: boolean
    pageSize: number // 每页多少条
    page: number // 第几页
}

// 获取用户身份信息
export async function getUserInfoServices(): Promise<ResDataType> {
    const url = `/api/user/info`
    const data = (await axios.get(url)) as ResDataType
    return data
}

// 用户注册
export async function registerServices(
    username: string,
    password: string,
    nickname?: string
): Promise<ResDataType> {
    const url = `/api/user/register`
    const paramsData = { username, password, nickname: nickname || username }
    const resData = (await axios.post(url, paramsData)) as ResDataType
    return resData
}

// 登录
export async function loginServices(username: string, password: string): Promise<ResDataType> {
    const url = `/api/user/login`
    const paramsData = { username, password }
    const resData = (await axios.post(url, paramsData)) as ResDataType
    return resData
}
